<template>
  <div>
    <h1>当前求和为: {{ bigSum }}</h1>
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="increment(n)">相加</button>
    <button @click="decrement(n)">-</button>
    <button @click="incrementOdd(n)">当前求和为奇数的时候加</button>
    <button @click="incrementWait(n)">等一等再加</button>
    <hr />
    <h2>学校为：{{ school }}</h2>
    <h3>学科为：{{ subject }}</h3>
    <div class="container">
      <div>
        <span  class="btn-group">
          <button>First</button>
          <button>Second</button>
        </span>
      </div>
      <div></div>
    </div>
  </div>
</template>

<script>
import { mapGetters, mapMutations, mapState } from 'vuex';
export default {
  name: 'count',
  data() {
    return {
      n: 1, // 用户选择的数字
    };
  },
  methods: {
    ...mapMutations('count', { increment: 'JIA' }),
    // increment() {
    //   this.$store.dispatch('jia', this.n);
    // },
    decrement() {},
    incrementOdd() {},
    incrementWait() {
      // 操作可以放在action中
      setTimeout(() => {}, 500);
    },
  },
  computed: {
    // 一个个写在computed中太麻烦
    // xuexiao() {
    //   return this.$store.state.school;
    // },
    // xueke() {
    //   return this.$store.state.subject;
    // },

    // mapState还有更简便的写法
    // ...mapState({ school: 'school', subject: 'subject' }),
    // ...mapState(['school', 'subject']),

    ...mapState('count', ['school', 'subject', 'sum']),
    // .....
    // bigSum() {
    //   return this.$store.getters.bigSum;
    // },
    ...mapGetters('count', ['bigSum']),
  },
};
</script>

<style lang="scss" scoped>
.container {
  width: 80vw;
  margin: 10vh auto;
  height: 1000px;
  position: relative;
  background-color: #e0c8d1;
  div:nth-child(1) {
    width: 200px;
    height: 200px;
    position: absolute;
    background: #482936;
    top: 0;
    transition: all 0.5s;
  }
  div:nth-child(2) {
    width: 200px;
    height: 200px;
    position: absolute;
    background: #482936;
    left: 250px;
    transition: all 0.5s;
  }
  div:hover {
    height: 300px;
    width: 300px;
    transform: translateX(-50px);
  }
}
</style>
